﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Invent
{
    public partial class frmGridForm : Form
    {
        private MySqlConnection Conn;
        private string Sql;

        public frmGridForm(MySqlConnection Connection, string txtSQL, bool State)
        {
            InitializeComponent();
            Conn = Connection;
            Sql = txtSQL;
            grdMain.DataSource = GetData(Sql);
            if (State) grdMain.ReadOnly = true;
        }

        private DataTable GetData(string sqlCommand)
        {
            MySqlCommand command = new MySqlCommand(sqlCommand, Conn);
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            adapter.SelectCommand = command;

            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            adapter.Fill(table);

            return table;
        }

    }
}
